"""
修改transcript文件
"""
import re


def file_r(path):
    with open(path, 'r', encoding="UTF-8") as f:
        return f.read()


def file_w(path, text, mode, encoding="UTF-8"):
    """
    用于向文件中写入

    :param path: 文件路径
    :param text: 要写入的数据
    :param mode: 写入模式 a为追加 w为覆写
    :param encoding: 文档编码格式

    """
    with open(path, mode, encoding=encoding) as f:
        f.write(text)


if __name__ == '__main__':
    file_str = file_r("transcript/1.txt")
    file_str = file_str.replace("非3星结束行动", "fei3xingjieshurenwu")
    file_str = file_str.replace("3星结束行动", "3xingjieshurenwu")
    file_str = file_str.replace("4星结束行动", "4xingjieshurenwu")
    file_str = file_str.replace("编入队伍", "bianruduiwu")
    file_str = file_str.replace("标题", "biaoti")
    file_str = file_str.replace("部署1", "bushu1")
    file_str = file_str.replace("部署2", "bushu2")
    file_str = file_str.replace("戳一下", "chuoyixia")
    file_str = file_str.replace("干员报到", "ganyuanbaodao")
    file_str = file_str.replace("观看作战记录", "guankanzuozhanjilu")
    file_str = file_str.replace("进驻设施", "jinzhusheshi")
    file_str = file_str.replace("晋升后交谈1", "jinshenghoujiaotan1")
    file_str = file_str.replace("晋升后交谈2", "jinshenghoujiaotan2")
    file_str = file_str.replace("精英化晋升1", "jingyinghuajinsheng1")
    file_str = file_str.replace("精英化晋升2", "jingyinghuajinsheng2")
    file_str = file_str.replace("任命队长", "renmingduizhang")
    file_str = file_str.replace("任命助理", "renmingzhuli")
    file_str = file_str.replace("问候", "wenhou")
    file_str = file_str.replace("闲置", "xianzhi")
    file_str = file_str.replace("信赖触摸", "xinlaichumo")
    file_str = file_str.replace("信赖提升后交谈1", "xinlaitishenghoujiaotan1")
    file_str = file_str.replace("信赖提升后交谈2", "xinlaitishenghoujiaotan2")
    file_str = file_str.replace("信赖提升后交谈3", "xinlaitishenghoujiaotan3")
    file_str = file_str.replace("行动出发", "xingdongchufa")
    file_str = file_str.replace("行动开始", "xingdongkaishi")
    file_str = file_str.replace("行动失败", "xingdongshibai")
    file_str = file_str.replace("选中干员1", "xuanzhongganyuan1")
    file_str = file_str.replace("选中干员2", "xuanzhongganyuan2")
    file_str = file_str.replace("作战中1", "zuozhanzhong1")
    file_str = file_str.replace("作战中2", "zuozhanzhong2")
    file_str = file_str.replace("作战中3", "zuozhanzhong3")
    file_str = file_str.replace("作战中4", "zuozhanzhong4")
    file_str = file_str.replace("交谈1", "jiaotan1")
    file_str = file_str.replace("交谈2", "jiaotan2")
    file_str = file_str.replace("交谈3", "jiaotan3")
    file_str = re.sub(r"[~？，！。“”]|\([^\n]*\)|\.", "", file_str)
    print(file_str)
    file_w("transcript/1.txt", file_str, "w")
